package com.diver.flinkdemo.Trd.fjdxy;

import com.alibaba.fastjson.JSONObject;
import com.diver.flinkdemo.entity.ResultConfig;
import com.diver.flinkdemo.service.IHttpService;
import com.diver.flinkdemo.service.impl.HttpServiceImpl;
import com.diver.flinkdemo.utils.FJSignUtils;
import com.diver.flinkdemo.utils.FlinkThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import java.util.HashMap;
import java.util.Map;

/**
 * @author hesc
 * @date 2022-08-22
 */
@Slf4j
public class FJDXYController {
    private FlinkThreadUtil threadUtil = new FlinkThreadUtil();

    private IHttpService httpService = new HttpServiceImpl();
    /**
     * 福建电信云助手平台推送数据
     * @param data
     */
    public void dianXYDeal(String data){
        threadUtil.threadPoolExecutor().submit(new Runnable() {
            @Override
            public void run() {
                log.info("福建电信云助手平台推送数据：{}", data);
                JSONObject jo = JSONObject.parseObject(data);
                String url = FJSignUtils.url + jo.getString("url");
                Map<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json");
                ContentType contentType = ContentType.APPLICATION_JSON;
                JSONObject params = jo.getJSONObject("params");
                ResultConfig<String> result = httpService.doStringEntityPost(url, headers, JSONObject.toJSONString(params), contentType, "utf-8");
                log.info("福建电信云助手平台推送数据{} 返回:{}", url, result);
            }
        });
    }
}
